<?php

namespace App\Http\Controllers;

use App\Models\SystemSetting;
use App\Services\ProductService;
use Inertia\Inertia;
use Inertia\Response;

class ProductController extends Controller
{
    protected $productService;

    public function __construct(ProductService $productService)
    {
        $this->productService = $productService;
    }
    /**
     * 显示产品详情页
     */
    public function show(string $slug): Response
    {
        $data = $this->productService->getProductDetails($slug);
        $relatedProducts = $this->productService->getRelatedProducts($data['raw_product']);

        return Inertia::render('Shop/Product', [
            'product' => $data['product'],
            'variants' => $data['variants'],
            'relatedProducts' => $relatedProducts,
            'systemSettings' => SystemSetting::getPublicSettings()
        ]);
    }

}
